package controller;

import dao.DrugDAOImpl;
import model.TDrug;
import model.TUser;
import utils.DispatcherUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "DrugmanageServlet", value = "/drugmanage.do")
public class DrugmanageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        TUser tUser = (TUser) session.getAttribute("loginuser");
        DrugDAOImpl drugDAO = new DrugDAOImpl();
        List<TDrug> ar = null;
        try {
             ar = drugDAO.getUserAllDrug(tUser.getUserid());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        request.setAttribute("list",ar);
        DispatcherUtils.openweb("drugmanage.jsp",request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
